package org.tgcloud.group.service.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.tgcloud.group.core.RedisUtil;
import org.tgcloud.group.core.mapUtils.GeoUtils;
import org.tgcloud.group.repository.MediaMapper;
import org.tgcloud.group.web.controller.dto.media.MediaAppBriefDTO;

import java.util.List;

/**
 * @Author: zhy
 * @Created: 2025-03-03-下午4:57
 * @Description:
 */
@Component
public class MediaTask {

    public Boolean doRefreshStatus = false;

    @Autowired
    private GeoUtils geoUtils;

    @Autowired
    private MediaMapper mediaMapper;

//    @Scheduled(cron = "0 45 2 * * ?")
    public void doRefreshRedis() {
        if (doRefreshStatus){
            if (RedisUtil.existKey(GeoUtils.GEO_KEY)){
                RedisUtil.deleteObject(GeoUtils.GEO_KEY);
            }
            List<MediaAppBriefDTO> appBriefDTOS = mediaMapper.selectAllTestList2();
            for (MediaAppBriefDTO dto : appBriefDTOS){
                double longitude = Double.parseDouble(dto.getLongitude());
                double latitude = Double.parseDouble(dto.getLatitude());
                geoUtils.geoAdd(dto.getId().toString(), longitude, latitude);
            }
        }
    }

}
